package com.twu.biblioteca;

import java.util.ArrayList;

public class User {
    private String username;
    private String password;
    private String email;
    private String phoneNumber;
    private String libraryNumber;

    private final int FirstLibraryNumber = 1111111;
    private static ArrayList<User> users = new ArrayList();

    public User(String username, String password, String email, String phoneNumber) {
        this.username = username;
        this.password = password;
        this.email = email;
        this.phoneNumber = phoneNumber;
        users.add(this);
        setLibraryNumber();
    }

    public String getUsername() {
        return username;
    }

    public String getEmail() {
        return email;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public String getPassword() {
        return password;
    }

    public String getLibraryNumber() {
        return libraryNumber;
    }

    private void setLibraryNumber() {
        int libraryNumber = FirstLibraryNumber + users.size() -1;
        this.libraryNumber = (libraryNumber / 10000) + "-" + (libraryNumber % 10000);
    }

    public static User logIn(String username, String password) {
        for (User user : users) {
            if ((user.getUsername().equals(username) || (user.getLibraryNumber().equals(username)))
                    && user.getPassword().equals(password))
                return user;
        }
        return null;
    }

}
